package middlewares

import (
	"github.com/labstack/echo/v4"
	"longmen/server/internal/services/nami/utils"
	"longmen/server/pkg/db/redis/cache"
)

func LotteryOperateClickCount(next echo.HandlerFunc) echo.HandlerFunc {
	return func(c echo.Context) error {
		ip := c.RealIP()
		cc := &c
		defer utils.SafeGo(func() {
			cache.SetLotteryIpClickCount(ip)
			cache.SetLotteryUvClickCount()

			if cc != nil {
				c := *cc
				_, ok := c.Get("uid").(int)
				if ok {
					cache.SetLotteryPvClickCount()
				}
			}
		})
		return next(c)
	}
}
